package com.example.algorithm.service.impl;

import com.example.algorithm.service.ArithmeticService;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @date 2024/8/26 16:54
 * @description
 */
@Service
public class ArithmeticServiceImpl  implements ArithmeticService {
    @Override
    public int binarySearch(int[] arr, int target) {
        int left=0;
        int right = arr.length-1;
        while (left<=right){
            int mid = (left+right)>>>1;
            if(target<arr[mid]){
                    right = mid-1;
            }else if(target>arr[mid]){
                left = mid+1;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
